<!--编辑个人信息-->
<template>
	<view class="info-edit">
		<view class="person-info-detail">
			<view class="personal-photos">
				<text>个人正面照</text>
				<image :src="personInfo.image_128" mode=""></image>
			</view>
			<sl-list title="姓名" :rightText="personInfo.name" reviseType="input" required :fieldModel="{modelId:modelId,fields:'name',fieldsType:'char',modelName:'res.partner',title:'姓名'}"></sl-list>
			<sl-list title="性别" reviseType="checkbox2" :fieldModel="{modelId:modelId,fields:'sex',fieldsType:'select',modelName:'res.partner',title:'性别',selectName:'sex'}"
			 :rightText="personInfo.sex?personInfo.sex:'未设定'" :rightColor="personInfo.sex?'':'#999'"></sl-list>
			<sl-list title="手机号码" :showArrow="false" :fieldModel="{modelId:modelId,fields:'mobile',fieldsType:'char',modelName:'res.partner',title:'手机号码'}"
			 :rightText="personInfo.mobile" required reviseType="input"></sl-list>
			<sl-list title="身份证号" :showArrow="false" :fieldModel="{modelId:modelId,fields:'idcard',fieldsType:'char',modelName:'res.partner',title:'身份证号'}"
			 :rightText="personInfo.idcard" required reviseType="input"></sl-list>
			<sl-list title="户籍地址" reviseType="input" :rightText="personInfo.address?personInfo.address:'未设定'" required
			 :rightColor="personInfo.address?'':'#999'" :fieldModel="{modelId:modelId,fields:'address',fieldsType:'char',modelName:'res.partner',title:'户籍地址'}"></sl-list>
		</view>
		<view class="person-info-detail">
			<sl-list title="工种/技能" reviseType="checkbox" :rightText="personInfo.work_type_name" :fieldModel="{modelId:modelId,fields:'work_type',many2oneModel:'jhj.bidding.tag',fieldsType:'many2one',modelName:'res.partner',title:'工种/技能'}"></sl-list>
			<sl-list title="工种等级" :rightText="personInfo.work_type_grade" reviseType="checkbox2" :fieldModel="{modelId:modelId,fields:'work_type_grade',fieldsType:'select',modelName:'res.partner',title:'工种等级',selectName:'work_type_grade'}"></sl-list>
			<sl-list title="文化程度" :rightText="personInfo.education_degree" reviseType="checkbox2" :fieldModel="{modelId:modelId,fields:'education_degree',fieldsType:'select',modelName:'res.partner',title:'文化程度',selectName:'education_degree'}"></sl-list>
			<sl-list title="工龄" :rightText="personInfo.work_years" reviseType="input" required :fieldModel="{modelId:modelId,fields:'work_years',fieldsType:'char',modelName:'res.partner',title:'工龄'}"></sl-list>
		</view>
		<view class="person-info-detail" v-if="personInfo.account_type=='劳务企业'">
			<sl-list title="企业名称" :rightText="companyInfo.name" required :fieldModel="{modelId:companyId,fields:'name',fieldsType:'char',modelName:'jhj.company',title:'公司名称'}"></sl-list>
			<sl-list title="社会统一信用编码" :rightText="companyInfo.code" required :fieldModel="{modelId:companyId,fields:'code',fieldsType:'char',modelName:'jhj.company',title:'社会统一信用代码'}"></sl-list>
			<!-- 	<sl-list title="企业联系人" :rightText="personInfo.education_degree" required></sl-list> -->
			<sl-list title="企业联系人电话" :rightText="companyInfo.mobile" required :fieldModel="{modelId:companyId,fields:'mobile',fieldsType:'char',modelName:'jhj.company',title:'联系人'}"></sl-list>
		</view>


		<view class="person-info-detail" v-if="personInfo.account_type=='班组长'">
			<sl-list title="班组名称" :rightText="teamInfo.name" :fieldModel="{modelId:teamId,fields:'name',fieldsType:'char',modelName:'jhj.team',title:'班组名称'}"
			 required></sl-list>
			<sl-list title="工种类型" reviseType="checkbox" :rightText="teamInfo.work_type_name" :fieldModel="{modelId:teamId,fields:'work_type',many2oneModel:'jhj.bidding.tag',fieldsType:'many2one',modelName:'jhj.team',title:'工种/技能'}"
			 required></sl-list>
			<sl-list title="带班工龄" :rightText="teamInfo.team_lead_years" :fieldModel="{modelId:teamId,fields:'team_lead_years',fieldsType:'char',modelName:'jhj.team',title:'带班工龄'}"
			 required></sl-list>
		</view>
	</view>
</template>

<script>
	import SlList from '@/components/sl-list/sl-list'
	import {
		getUserInfo,
		getTeamInfo,
		getCompanyInfo
	} from '@/static/js/api/user.js'
	export default {
		components: {
			SlList
		},
		data() {
			return {
				personInfo: {},
				modelId: '',
				fieldModel: {},
				teamInfo: {},
				teamId: '',
				companyInfo: {},
				companyId: ''
			}
		},
		onLoad(data) {

		},
		mounted() {
			let self = this;
			let userInfo = JSON.parse(uni.getStorageSync('userInfo'));
			self.modelId = userInfo.partner_id;
			self.getAccountInfo();
			uni.$on('reviseData', function(data) {
				self.getAccountInfo();
				if (userInfo.account_type == '班组长') {
					self.getTeamInfo()
				}
				if (userInfo.account_type == '劳务企业管理人员') {
					self.getCompanyInfo()
				}
			})
			if (userInfo.account_type == '班组长') {
				this.getTeamInfo()
			}
			if (userInfo.account_type == '劳务企业管理人员') {
				this.getCompanyInfo()
			}
		},
		methods: {
			//获取用户详细信息
			getAccountInfo() {
				getUserInfo().then(res => {
					let _res = res[0];
					this.personInfo = _res;
					this.personInfo.image_128 = 'data:image/png;base64,' + _res.image_128
				})

				// this.api.read('res.partner', id,
				// 	'name,sex,mobile,idcard,address,work_type,work_years,account_type,education_degree,work_type_grade').then(
				// 	res => {
				// 		let _res = res[0];
				// 		this.personInfo = _res;
				// 	})


			},
			getTeamInfo() {
				getTeamInfo().then(res => {
					this.teamInfo = res.data[0]
					this.teamId = this.teamInfo.id;
				})
			},
			getCompanyInfo() {
				getCompanyInfo().then(res => {
					
					this.companyInfo = res[0];
					this.companyId = this.companyInfo.id;
				})
			}

		}
	}
</script>

<style lang="less" scoped>
	.info-edit {
		background: #F4F5F9;
	}

	.person-info-detail {
		background: #FFFFFF;
		margin-bottom: 20rpx;
		padding-bottom: 5rpx;
	}

	.personal-photos {
		padding: 16rpx 34rpx;
		display: flex;
		align-items: center;
		border-bottom: 2rpx solid #F4F5F9;

		text {
			flex: 1;
			font-size: 30rpx;
			color: #333333;
		}

		image {
			width: 128rpx;
			height: 128rpx;
			background: #D7D9E2;
			border-radius: 12rpx;
		}
	}

	.skill {
		margin-top: 22rpx;
	}
</style>
